package com.qidianit.mes.production.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qidianit.mes.common.pojo.MesResult;
import com.qidianit.mes.pojo.Craft;
import com.qidianit.mes.production.mapper.CraftMapper;
import com.qidianit.mes.production.service.CraftService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2025/8/5 10:25
 * @description
 */
@Service
@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,readOnly = false)
public class CraftServiceImpl extends ServiceImpl<CraftMapper, Craft> implements CraftService {
    @Override
    @Transactional(readOnly = true)// 查询配置为只读事务
    public MesResult<Page<Craft>> getCraftList(int pageNun, int pageSize, Craft craft) {
        Page<Craft> page = new Page<>(pageNun, pageSize);
        QueryWrapper<Craft> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(craft != null && StringUtils.isNoneBlank(craft.getCraftCode()), "craft_code", craft.getCraftCode());
        queryWrapper.like(craft != null && StringUtils.isNoneBlank(craft.getCraftName()), "craft_name", craft.getCraftName());
        queryWrapper.eq(craft != null && craft.getIsEnable() != null, "is_enable", craft.getIsEnable());
        return MesResult.success(this.page(page, queryWrapper));
    }
}
